load C:\Manoj\projects\ace\Julia_W_new.mat w_climate Julia_W fday w julia_model_drift ;
load c:\manoj\projects\ace\substorm;
% load c:\manoj\projects\substorm\selected_substorm;
% fday_substorm = selected_substorm;
Julia_fday = floor(fday(:,1));
%fday_substorm = non_selected_substorm;

%load c:\manoj\projects\ace\rand_substorm;


% kk = rand([1,4193]);
% fday_substorm = sort(kk)*2.1780e+003;

st = 14/24;
en = 20/24;
i_counter=0;
radius_epoch = 1/24;

for i = 1:length(fday_substorm),
    
    
    if fday_substorm(i)-floor(fday_substorm(i)) > st & ...
            fday_substorm(i)-floor(fday_substorm(i)) < en,
        
       [fday_int,ii] = intersect(Julia_fday,floor(fday_substorm(i)));
       if ~isempty(fday_int),
           
           if fday_substorm(i)-radius_epoch >= fday(ii,Julia_W(ii).k(1)) &...
               fday_substorm(i)+radius_epoch <= fday(ii,Julia_W(ii).k(end)),
           i_counter = i_counter+1;
           
           L = fday(ii,:) >= (fday_substorm(i) + 1e-5 ) - radius_epoch & ...
               fday(ii,:) <= (fday_substorm(i) + 1e-5 ) + radius_epoch;
           %1e-5 is to give a small offset to avoid fday_substorm at
           %exact time as a JULIA recording (hope so)
           
           w(ii,:) = w(ii,:) - nanmean(w); % remove the daily forcing
           
           SEG_JULI(i_counter,:) = w(ii,L);
           
           end;
       end;
    end;
end;

plot((-radius_epoch*1440) + 2.5 : 5 :  (radius_epoch*1440) - 2.5 ,nanmean(SEG_JULI) * 24.366*1e-3 );
